package com.rskj.cashbook.response;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author fudaopin
 */

@Data
@Accessors(chain = true)
public class ResponseEntity<T> {
    private String message;
    private T data;
    private int code;
    private String cause;
    private int status;
    private boolean success;

    public static ResponseEntity<String> fail(String message) {
        return new ResponseEntity<String>()
                .setMessage(message)
                .setData(message)
                .setCause(message)
                .setCode(500)
                .setSuccess(false);
    }

    /**
     * 通用失败方法，支持泛型
     */
    public static <T> ResponseEntity<T> failGeneric(String message) {
        return new ResponseEntity<T>()
                .setMessage(message)
                .setData(null)
                .setCause(message)
                .setCode(500)
                .setSuccess(false);
    }

    public static <T> ResponseEntity<T> ok(T message) {
        return new ResponseEntity<T>()
                .setData(message)
                .setMessage("success")
                .setCause("OK")
                .setCode(200)
                .setSuccess(true);
    }
}
